from datetime import datetime

from django.db import models

from users.models import User


class Spit(models.Model):
    # 吐槽内容
    content = models.CharField(max_length=200, verbose_name='吐槽内容')
    publishtime = models.DateTimeField(auto_now_add=True, verbose_name='发布日期')
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='发布人ID')
    nickname = models.CharField(max_length=20, null=True, verbose_name='发布人昵称')
    visits = models.IntegerField(default=0, null=True, verbose_name='浏览量')
    thumbup = models.IntegerField(default=0, null=True, verbose_name='点赞数')
    comment = models.IntegerField(default=0, null=True, verbose_name='回复数')
    avatar = models.ImageField(verbose_name='用户的头像', null=True)
    parent = models.ForeignKey('self', on_delete=models.CASCADE, null=True, verbose_name='上级ID')
    collected = models.BooleanField(default=False, verbose_name='是否收藏')
    hasthumbup = models.BooleanField(default=False, verbose_name='是否点赞')

    class Meta:
        db_table = "tb_spit"
        verbose_name = "吐槽表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.content
